package indi.jp.project.business.pub.controller;

import indi.jp.project.business.pub.pojo.po.MaterialPO;
import indi.jp.project.business.pub.pojo.query.MaterialQuery;
import indi.jp.project.core.entity.JsonResult;
import indi.jp.project.business.pub.service.MaterialService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;

@RestController
@RequestMapping("/pub/material")
public class MaterialController {

    @Resource
    private MaterialService materialService;

    @GetMapping("/queryGrid")
    public JsonResult queryGrid(MaterialQuery query, HttpServletRequest request) throws SQLException {
        String account = request.getParameter("account");
        query.setLander(account);
        return materialService.queryGrid(query);
    }

    @PostMapping("/save")
    public JsonResult save(@RequestBody MaterialPO materialPO, HttpServletRequest request) throws SQLException {
        String account = request.getParameter("account");
        materialPO.setCreateBy(account);
        materialPO.setModifyBy(account);
        return materialService.save(materialPO);
    }

    @PostMapping("/deleteById")
    public JsonResult delete(@RequestParam String id) throws SQLException {
        return materialService.deleteById(id);
    }

}
